<template>
    <div class="qingwu">
        <div class="admin_table_page_title">电表抄读记录</div>
        <div class="unline underm"></div>

        <div class="admin_table_handle_btn">
            <a-form layout="inline" :form="form"  @submit="handleSubmit">

                <a-form-model-item label="区域">

                    <a-select style="width: 200px"  default-value="请选择区域" placeholder="请选择区域"  @change="onCommunity" >
                        <a-select-option  value="">
                            请选择区域
                        </a-select-option>
                        <a-select-option :key="id" v-for="(val,k) in community_options" :value="community_options[k]['id']">
                            {{community_options[k]['name']}}
                        </a-select-option>

                    </a-select>
                </a-form-model-item>

                <a-form-item label="用户名">
                    <a-input v-model="username"  placeholder="请输入用户名"  />
                </a-form-item>
                <a-form-item label="手机号">
                    <a-input v-model="mobile"   placeholder="请输入手机号"/>
                </a-form-item>

                <a-form-item label="创建时间">

                    <a-range-picker v-model="change" @change="onChanged" />
                </a-form-item>

                <a-form-model-item >
                    <a-button icon="search" @click="search">
                        查询
                    </a-button>
                </a-form-model-item>
                <a-form-model-item >
                    <a-button  @click="reset">重置</a-button>
                </a-form-model-item>
            </a-form>
        </div>

        <div class="admin_table_list">
            <a-table :columns="columns" :data-source="list" :pagination="false" :row-selection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }" row-key="id">



                <div slot="userdata" slot-scope="rows">
                    <p>姓名: {{rows.username}}</p>
                    <p>手机号: {{rows.mobile}}</p>
                </div>


                <span slot="action" slot-scope="rows">
                    <a-button size="small" icon="edit" @click="$router.push('/Admin/users/form/'+rows.id)">编 辑</a-button>
                </span>

                <span slot="status" slot-scope="rows">
                    <a-switch v-if="rows.status == 1" checked-children="正常" un-checked-children="禁用" @change="onChangeStatus(rows.id)" default-checked/>
                    <a-switch v-else checked-children="正常" @change="onChangeStatus(rows.id)" un-checked-children="禁用" />
                </span>
            </a-table>
            <div class="admin_pagination" v-if="total>0">
                <a-pagination v-model="params.page" :page-size.sync="params.per_page" :total="total" @change="onChange" show-less-items />
            </div>
        </div>
    </div>
</template>

<script>
export default {
    components: {},
    props: {},
    data() {
      return {
          params:{
              page:1,
              per_page:30,
          },
          total:0, //总页数
          selectedRowKeys:[], // 被选择的行
          columns:[
              {title:'#',dataIndex:'id',fixed:'left'},
              {title:'表地址',dataIndex:'meter_code'},
              {title:'区域',dataIndex:'community.name'},
              {title:'绑定用户',scopedSlots: { customRender: 'userdata' }},
              {title:'抄表度数',dataIndex:'total_count'},
              {title: '上次抄表度数', dataIndex:'last_count'},
              {title: '电费总计', dataIndex:'total_cost'},
              {title:'抄读时间',dataIndex:'create_time'},
              {title:'操作',key:'id',fixed:'right',scopedSlots: { customRender: 'action' }},
          ],
          list:[],
          username:'',  // 名称
          mobile:'',     // 手机号
          community_options:[],
      };
    },
    watch: {},
    computed: {},
    methods: {
        // 选择框被点击
        onSelectChange(selectedRowKeys) {
            this.selectedRowKeys = selectedRowKeys;
        },
        // 选择分页
        onChange(e){
            this.params.page = e;
        },
        //时间
        onChanged(date, dateString) {
            this.change = dateString
            console.log(date, dateString);
        },
        // 获取区域列表
        get_community(){
            this.$get(this.$api.estateElectricCommunity).then(res=>{
                this.community_options = res.data.data;
                // console.log(this.community_options)
            })
        },
        // 区域事件
        onCommunity(value, selectedOptions){
            this.agent = value;
        },
        onload(){
            this.$get(this.$api.estateMeterSettlement,this.params).then(res=>{
                this.total = res.data.total;
                this.list = res.data.data;
            });
        },
        // 重置
        reset(){
            location.reload();
        },

        // 搜索
        search(){
            this.params['username'] = this.username;
            this.params['mobile'] = this.mobile;
            this.params['community_id'] = this.agent;
            this.params['change'] = this.change;
            this.$get(this.$api.estateMeterSettlement,this.params).then(res=>{
                this.total = res.data.total;
                this.list = res.data.data;
            });
        },
    },
    created() {
        this.onload();
        this.get_community();
        // this.getCommunityList();/**/
    },
    mounted() {}
};
</script>
<style lang="scss" scoped>

</style>
